<template>
	<view class="content">
		<view class="row b-b">
			<view class="textop">收款人</view>
		    <input class="input" type="text" v-model="uname" placeholder="请填写姓名" placeholder-style='text-align:right'/>
		</view>
		<view class="row b-b">
			<view class="textop">身份证号码</view>
		    <input class="input" type="text" v-model="certificates" placeholder="请填写身份证号" placeholder-style='text-align:right' />
		</view>
		<view class="row b-b">
			<view class="textop">开户行</view>
			<input class="input" type="text" v-model="kaihuhang" placeholder="请填写开户行" placeholder-style='text-align:right' />
		</view>
		<view class="row b-b">
			<view class="textop">银行卡号</view>
		    <input class="input" type="number" v-model="banknumer" placeholder="请填写银行卡号" placeholder-style='text-align:right' />
		</view>
		<view class="row b-b">
			<view class="textop">手机号码</view>
		    <input class="input" type="number" v-model="phone" placeholder="请填写银行预留手机号" placeholder-style='text-align:right' />
		</view>
		<view class="row b-b">
			<view class="textop">短信验证码:</view>
			<input class="input" type="number" v-model="vcode" maxlength="8" placeholder="验证码" placeholder-style='text-align:right' />
			<view class="verify-code-selection">
				<text class="btn-get-code" @click="getCode">{{textcode}}</text>
			</view>
		</view>
		<button class="add-btn" @click="confirm">确定</button>
	</view>
</template>

<script>
	import { mapActions } from 'vuex'
	
	export default {
		data() {
			return {
					arrList:[],
					uname: '',//姓名
					certificates : '',// 身份证号
					bankNameid: '', //银行id
					index: 0,
					kaihuhang:'',//开户行
					banknumer: '', //银行卡号
					verShow: true,
					phone: '',
					vcode: '',
					textcode: '获取验证码'
			}
		},
		onLoad(option){
			this.initDat();
		},
		methods: {
			// bindPickerChange: function(e) {
			// 	this.index = e.target.value;
			// 	this.bankNameid = this.arr[e.target.value].id;
			// },
			//验证码
			//初始化数据
			initDat(){
				this.$http.post('bindcardinfo').then(res => {
					this.uname = res.data.truename;
					this.certificates = res.data.idcard;
					this.kaihuhang = res.data.bank_name;
					this.banknumer = res.data.bank_number;
					this.phone = res.data.bank_phone;
					
				})
			},
			getCode(){
				if(this.verShow){
					if(!/(^1[3|4|5|7|8][0-9]{9}$)/.test(this.phone)){
						this.$api.msg('请输入正确的手机号码');
						return;
					}
					uni.request({
						url: this.$common.baseUrl + "/api/user/sendSMS",
						dataType: 'json', //默认 json格式
						data: {
							mobile:this.phone
						},
						method: 'POST', //请求方式
						header: {
							'content-type': 'application/x-www-form-urlencoded', //默认值
						},
						success: (res) => {
						},
						fail: (error) => {
							
						}
					})
					  this.verShow = false; 
					  this.textcode = 60;
		              var auth_timer = setInterval(()=>{
		                this.textcode--;
		                if(this.textcode<=0){
		                  this.verShow = true;
						  this.textcode = '获取验证码';
		                  clearInterval(auth_timer);
		                }
		              },1000)
						
				}
			},
			//提交
			confirm(){
				if(!this.uname){
					this.$api.msg('请输入借款人');
					return;
				}
				if(!this.certificates){
					this.$api.msg('请输入身份证号');
					return;
				}
				if(!/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(this.certificates)){
					this.$api.msg('请输入正确的身份证号码');
					return;
				}
				if(!this.kaihuhang){
					this.$api.msg('请输入开户行');
					return;
				}
				if(!this.banknumer){
					this.$api.msg('请输入银行卡号');
					return;
				}
				// var regex = /^(998801|998802|622525|622526|435744|435745|483536|528020|526855|622156|622155|356869|531659|622157|627066|627067|627068|627069)\d{10}$/;  
				// if(!regex.test(this.banknumer)){
				// 	this.$api.msg('请输入正确的银行卡号');
				// 	return;
				// }
				if(!this.phone){
					this.$api.msg('请输入手机号');
					return;
				}
				if(!/(^1[3|4|5|7|8][0-9]{9}$)/.test(this.phone)){
					this.$api.msg('请输入正确的手机号码');
					return;
				}
				if(!this.vcode){
					this.$api.msg('请输入验证码');
					return;
				}
				let obj = {
					truename: this.uname,
					idcard: this.certificates,
					bank_name: this.kaihuhang,
					bank_number: this.banknumer,
					bank_phone: this.phone,
					code: this.vcode
				}
				this.$http.post('bindcard', obj).then(res => {
					this.$api.msg(res.msg);
					if(res.code == 1){
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 800)
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.row{
		display: flex;
		justify-content: flex-start;
		align-items: center;
		position: relative;
		padding:0 30upx;
		height: 110upx;
		background: #fff;
		line-height: 110upx;
		.input{
			flex: 1;
			font-size: 30upx;
			color: $font-color-dark;
			margin-left: 40upx;
			margin-top: 6upx;
			border-width:0;
			text-align:right;
		}
		.textop{
			font-size: $font-base + 2upx;
		}
		picker{
			font-size: 30upx;
			color: $font-color-dark;
			position: absolute;
			right: 27upx;
		}
	}
	.add-btn{
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690upx;
		height: 80upx;
		margin: 60upx auto;
		font-size: $font-lg;
		color: #fff;
		background-color: $base-index-color;
		border-radius: 10upx;
		box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
	}
	.btn-get-code {
		display: flex;
		align-items: center;
		font-size: $font-base - 6upx;
		letter-spacing: 4upx;
		height: 60upx;
		color: $base-index-color;
		border-radius: 10upx;
		// border-left: 1px solid #C0C4CC;
		padding: 4upx 20upx;
	}
</style>
